package com.interagriculture.controller;

import com.interagriculture.annotation.AdminVerify;
import com.interagriculture.common.Result;
import com.interagriculture.entity.UserInfo;
import com.interagriculture.service.UserInfoService;
import org.apache.ibatis.annotations.Delete;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;

/**
 * @author 10 2024/10/24
 */
@RestController
@RequestMapping("/adminUserInfo")
public class AdminUserInfoController {

     private static final Logger log = LoggerFactory.getLogger(AdminUserInfoController.class);
     @Resource
     private UserInfoService userInfoService;
     /**
      * 添加或更新成员信息
      */
     @PostMapping("/saveOrUpdateInfo")
     @AdminVerify
     public Result saveOrUpdateInfo(@RequestBody UserInfo userInfo) {
          log.info("修改或新增成员:{}",userInfo);
          userInfoService.saveOrUpdateInfo(userInfo);
          return Result.ok();
     }

     @GetMapping("/{id}")
//     @AdminVerify
     public Result<UserInfo> getById(@PathVariable @NotNull Integer id){
          return Result.ok(userInfoService.selectById(id));
     }

     @DeleteMapping("/delete")
     @AdminVerify
     public Result deleteById(@RequestParam @NotNull Integer id){
          userInfoService.deleteById(id);
          return Result.ok("删除成功");
     }
}
